<script type="text/javascript">	
<!--
$(function() {

	$( "#ngaybd" ).datepicker({
								showOtherMonths: true,
								selectOtherMonths: true,
								changeMonth: true,								
								dateFormat: "dd-mm-yy",
								showOn: "both",
								buttonImage:$('#root').val()+"img/calendar.jpg",
								buttonImageOnly: true
	 							});
	$( "#ngaykt" ).datepicker({
		showOtherMonths: true,
		selectOtherMonths: true,
		changeMonth: true,								
		dateFormat: "dd-mm-yy",
		showOn: "both",
		buttonImage:$('#root').val()+"img/calendar.jpg",
		buttonImageOnly: true
			});
	$("#ngaybd").change(function(){
									date = $.datepicker.parseDate('dd-mm-yy',$("#ngaybd").val());
									var nam = date.getFullYear();
									var thang = date.getMonth();
									var ngay = date.getDaysInMonth();
									var newdate = new Date(nam,thang,ngay);
									newdate = $.datepicker.formatDate('dd-mm-yy', newdate);
									$("#ngaykt").datepicker( "option", "minDate",date);
									$("#ngaykt").datepicker( "option", "maxDate",newdate);
									});
});
	
//-->
</script>
<div class="index">
<h2>Kế hoạch bán hàng lưu động</h2>
<?php
$numhh = count($hanghoas); 
echo $form->create('Chitieungay');
echo $form->input('root',array('id'=>'root','type'=>'hidden','value'=>$this->webroot));
?>
<table>
  <tr>
    <th><?php echo $form->input('ngaybd',array('id'=>'ngaybd','type'=>'text','label'=>'Từ','value'=>date('d-m-Y',strtotime($ngaybd))));?></th>
    <th><?php echo $form->input('ngaykt',array('id'=>'ngaykt','type'=>'text','label'=>'Đến','value'=>date('d-m-Y',strtotime($ngaykt))));?></th>
  	<th><?php echo $js->submit('  Xem  ', array(
								'url'=> array('controller'=>'kehoachbhlds','action'=>'laychitieu',$nhanvien_id),
 								'update' => '#kh'));?></th>
  </tr>
</table>
<div id='kh'>
<table id ='tables'>
<tr>
<th rowspan=2>STT</th>
<th rowspan=2>Đội</th>
<th rowspan=2>Địa Điểm</th>
<th rowspan=2>Ngày</th>
<th rowspan=2>Thành viên tham gia</th>
<th colspan=<?php echo $numhh?>>Chỉ tiêu</th>
<th rowspan=2>Ghi chú</th>
<th rowspan=2>Thao tác</th>
</tr>
<tr>
<?php foreach ($hanghoas as $keyhh =>$valhh):?>
<th><?php echo $valhh ?></th>
<?php endforeach;?>
</tr>
<?php
	$i=0; 
	 foreach ($chitieungays as $chitieungay):
	  $i++;
?>
<tr>
<td><?php echo $i?></td>
<td><?php echo $chitieungay['Kehoachbhld']['tendoi']?></td>
<td><?php echo $chitieungay['Kehoachbhld']['diadiem']?></td>
<td><?php echo date('d-m-Y',strtotime($chitieungay['Kehoachbhld']['thoigian']))?></td>
<td><?php echo $chitieungay['Kehoachbhld']['nhansu']?></td>
<?php foreach ($hanghoas as $keyhh =>$valhh):?>
<td>
<?php
	foreach ($chitieungay['Chitieungay'] as $ctngay)
	{
		if($ctngay['hanghoa_id']==$keyhh)
 			echo $ctngay['soluong'];	
	}
?>
</td>
<?php endforeach;?>
<td><?php echo $chitieungay['Kehoachbhld']['ghichu']?></td>
<td>
<?php echo $html->link('Sửa chỉ tiêu',array('controller'=>'chitieungays','action'=>'suachitieu',$chitieungay['Kehoachbhld']['id']));?>
<?php echo $html->link('Xóa',array('controller'=>'chitieungays','action'=>'xoakehoach',$chitieungay['Kehoachbhld']['id']), null, sprintf(__('Bạn muốn xóa %s ngày %s?', true), $chitieungay['Kehoachbhld']['tendoi'],date('d-m-Y',strtotime($chitieungay['Kehoachbhld']['thoigian']))));?>
</td>
</tr>
<?php endforeach;?> 
</table>
	<p>
	<?php
echo $this->Paginator->counter(array(
	'format' => __('Trang %page%/%pages%, hiện có %count% mẫu tin', true)
	));
	?>	</p>

	<div class="paging">
		<?php echo $this->Paginator->prev('<< ' . __('Trước', true), array(), null, array('class'=>'disabled'));?>
	 | 	<?php echo $this->Paginator->numbers();?>
 |
		<?php echo $this->Paginator->next(__('Sau', true) . ' >>', array(), null, array('class' => 'disabled'));?>
	</div>
</div> <!-- end div table -->
<?php echo $form->end();?>
</div>